//
// Created by PC on 2023/6/15.
// 按学生总成绩排序
//

#include <iostream>
using namespace std;

int main()
{
    struct student{
        string name;
        double math;
        double chinese;
        double english;
        double science;
        double total;
        void sum()
        {
            total = math+chinese+english+science;
        }
    };
    int n = 5;
    student stus[n];
    stus[0]={"Nasa",99,99.9,100,99};
    stus[1]={"WuBeiMo",90,92.9,90.9,93};
    stus[2]={"ShangGuan",88.5,99.9,100,99};
    stus[3]={"NanNan",93.5,99.9,100,99};
    stus[4]={"lin",99,99.3,100,99};
    // 计算总分数, 存入sum中
    for (int i = 0; i < n; ++i)
        stus[i].sum();
    // 冒泡排序
    for (int i = 0; i < n; ++i)
    {
        for (int j = 1; j < n - i; ++j)
        {
            if(stus[j-1].total>stus[j].total)
                swap(stus[j-1],stus[j]);
        }
    }
    for (int j = 0; j < n; ++j)
        printf("%d,%s,%0.2f\n",j,stus[j].name.c_str(),stus[j].total);
    return 0;
}